﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


namespace FAP.DataAccess.BLL
{
    public class taikhoan
    {
        public int id { get; set; }
        public string tendangnhap { get; set; }
        public string matkhau { get; set; }
        public string email { get; set; }
        public string cookie { get; set; }
        public DateTime ngayhethan { get; set; }
        public int websiteid { get; set; }
        public int trangthai { get; set; }
        public bool isdeleted { get; set; }
        //public website website { get { return website.websiteSelectRow(websiteid); } }

        #region taikhoanSelectAll
        public static List<taikhoan> taikhoanSelectAll()
        {
            IDataReader dr = FAP.DataAccess.DAL.taikhoanSelectAll();
            List<taikhoan> taikhoanList = new List<taikhoan>();
            while (dr.Read())
            {
                taikhoan mytaikhoan = new taikhoan
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendangnhap = !dr.IsDBNull(dr.GetOrdinal("tendangnhap")) ? (string)dr["tendangnhap"] : null,
                    matkhau = !dr.IsDBNull(dr.GetOrdinal("matkhau")) ? (string)dr["matkhau"] : null,
                    email = !dr.IsDBNull(dr.GetOrdinal("email")) ? (string)dr["email"] : null,
                    cookie = !dr.IsDBNull(dr.GetOrdinal("cookie")) ? (string)dr["cookie"] : null,
                    ngayhethan = !dr.IsDBNull(dr.GetOrdinal("ngayhethan")) ? (DateTime)dr["ngayhethan"] : DateTime.Now,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                taikhoanList.Add(mytaikhoan);
            }
            dr.Close();
            dr.Dispose();
            return taikhoanList;
        }
        #endregion

        #region taikhoanSelectRow
        public static taikhoan taikhoanSelectRow(int id)
        {
            IDataReader dr = FAP.DataAccess.DAL.taikhoanSelectRow(id);
            taikhoan taikhoan = null;

            if (dr.Read())
            {
                taikhoan = new taikhoan
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendangnhap = !dr.IsDBNull(dr.GetOrdinal("tendangnhap")) ? (string)dr["tendangnhap"] : null,
                    matkhau = !dr.IsDBNull(dr.GetOrdinal("matkhau")) ? (string)dr["matkhau"] : null,
                    email = !dr.IsDBNull(dr.GetOrdinal("email")) ? (string)dr["email"] : null,
                    cookie = !dr.IsDBNull(dr.GetOrdinal("cookie")) ? (string)dr["cookie"] : null,
                    ngayhethan = !dr.IsDBNull(dr.GetOrdinal("ngayhethan")) ? (DateTime)dr["ngayhethan"] : DateTime.Now,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,

                };
            }
            dr.Close();
            dr.Dispose();
            return taikhoan;
        }
        #endregion

        #region taikhoanSelectRow_CanUp
        public static taikhoan taikhoanSelectRow_CanUp(int idbaiviet)
        {
            IDataReader dr = FAP.DataAccess.DAL.taikhoanSelectRow_CanUp(idbaiviet);
            taikhoan taikhoan = null;

            if (dr.Read())
            {
                taikhoan = new taikhoan
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendangnhap = !dr.IsDBNull(dr.GetOrdinal("tendangnhap")) ? (string)dr["tendangnhap"] : null,
                    matkhau = !dr.IsDBNull(dr.GetOrdinal("matkhau")) ? (string)dr["matkhau"] : null,
                    email = !dr.IsDBNull(dr.GetOrdinal("email")) ? (string)dr["email"] : null,
                    cookie = !dr.IsDBNull(dr.GetOrdinal("cookie")) ? (string)dr["cookie"] : null,
                    ngayhethan = !dr.IsDBNull(dr.GetOrdinal("ngayhethan")) ? (DateTime)dr["ngayhethan"] : DateTime.Now,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,

                };
            }
            dr.Close();
            dr.Dispose();
            return taikhoan;
        }
        #endregion

        #region taikhoanSelectRowByForeignKey_websiteid
        public static List<taikhoan> taikhoanSelectRowByForeignKey_websiteid(int websiteid)
        {
            IDataReader dr = FAP.DataAccess.DAL.taikhoanSelectRowByForeignKey_websiteid(websiteid);
            List<taikhoan> taikhoanList = new List<taikhoan>();
            while (dr.Read())
            {
                taikhoan mytaikhoan = new taikhoan
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    tendangnhap = !dr.IsDBNull(dr.GetOrdinal("tendangnhap")) ? (string)dr["tendangnhap"] : null,
                    matkhau = !dr.IsDBNull(dr.GetOrdinal("matkhau")) ? (string)dr["matkhau"] : null,
                    email = !dr.IsDBNull(dr.GetOrdinal("email")) ? (string)dr["email"] : null,
                    cookie = !dr.IsDBNull(dr.GetOrdinal("cookie")) ? (string)dr["cookie"] : null,
                    ngayhethan = !dr.IsDBNull(dr.GetOrdinal("ngayhethan")) ? (DateTime)dr["ngayhethan"] : DateTime.Now,
                    websiteid = !dr.IsDBNull(dr.GetOrdinal("websiteid")) ? (int)dr["websiteid"] : 0,
                    trangthai = !dr.IsDBNull(dr.GetOrdinal("trangthai")) ? (int)dr["trangthai"] : 0,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                taikhoanList.Add(mytaikhoan);
            }
            dr.Close();
            dr.Dispose();
            return taikhoanList;
        }
        #endregion

        #region taikhoanInsertRow
        public static void taikhoanInsertRow(string tendangnhap, string matkhau, string email, string cookie, DateTime ngayhethan, int websiteid, int trangthai, bool isdeleted)
        {
            FAP.DataAccess.DAL.taikhoanInsertRow(tendangnhap, matkhau, email, cookie, ngayhethan, websiteid, trangthai, isdeleted);
        }
        #endregion

        #region taikhoanUpdateRow
        public static void taikhoanUpdateRow(int id, string tendangnhap, string matkhau, string email, string cookie, DateTime ngayhethan, int websiteid, int trangthai, bool isdeleted)
        {
            FAP.DataAccess.DAL.taikhoanUpdateRow(id, tendangnhap, matkhau, email, cookie, ngayhethan, websiteid, trangthai, isdeleted);
        }
        #endregion

        #region taikhoanDeleteRow
        public static void taikhoanDeleteRow(int id)
        {
            FAP.DataAccess.DAL.taikhoanDeleteRow(id);
        }
        #endregion
    }
}